############################################################################
#    Copyright (C) 2007 by Jo Walsh <jo@frot.org>                          #
#    Copyright (C) 2007 Terradue SRL                                       #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as               #
#    published by the Free Software Foundation; either version 2 of the    #
#    License, or (at your option) any later version.                       #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public             #
#    License along with this program; if not, write to the                 #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

from sys import argv
from os import system, walk
from glob import glob
from distutils.core import setup
from distutils.command.install import INSTALL_SCHEMES
# Tell distutils to put the data_files in platform-specific installation
# locations. See here for an explanation:
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
for scheme in INSTALL_SCHEMES.values():
    scheme['data'] = scheme['purelib']

locale_files = []
if 'build' in argv or 'install' in argv:
	for rdir, sdir, files in walk('duetopia'):
		pofiles = glob(rdir + '/*.po')
		if pofiles:
			for pofile in pofiles:
				print "compiling", pofile
				cmd = "msgfmt --check-format -o %s.mo %s" % (pofile[:-3], pofile)
				system(cmd)
			locale_files.append((rdir, glob(rdir + '/*[pm]o')))

pkg_config = {
	'name': 'register',
	'author': 'Jo Walsh',
	'author_email': 'jo.walsh@terradue.com',
	'url': 'http://www.terradue.com/duetopia/register',
	'keywords': 'metadata index web application geospatial search',
	'description': 'Collaborative application for metadata maintenance and search',
	'long_description': """
An application toolset using Django to provide a collaborative metadata manager/editor
over the web, plus search and query interfaces that are at least equivalent to those
mandated by the text of the INSPIRE Directive establishing a spatial data infrastructure
in Europe.
	""",
	'packages': [
		'duetopia',
		'duetopia.register',
		'duetopia.register.models',
	],
	'data_files': [
		('duetopia/register/static', glob('duetopia/register/static/*.js')),
		('duetopia/register/static', glob('duetopia/register/static/*.css')),
		('duetopia/register/static/img', glob('duetopia/register/static/img/*.png')),
		('duetopia/register/templates/register', glob('duetopia/register/templates/register/*.html')),
		('duetopia/register/models/sql', glob('duetopia/register/models/sql/*.sql')),
	] + locale_files,
	'license': 'GPL',
	'platforms': ['all'],
    'version': '0.1',
    'install_requires': ['django >= 1.0','owslib >= 0.3'],
}

if __name__ == '__main__':
	from distutils.core import setup
	from os import environ

	if "DUETOPIA_VERSION" in environ:
		pkg_config['version'] = environ["DUETOPIA_VERSION"]

	setup(**pkg_config)
